package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.teach.domain.NbChapterMaterialVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.NbChapterMaterial;
import com.ruoyi.teach.service.INbChapterMaterialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 章节/学习资料Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/chapter_material")
public class NbChapterMaterialController extends BaseController
{
    @Autowired
    private INbChapterMaterialService nbChapterMaterialService;

    /**
     * 查询章节/学习资料列表
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_material:list')")
    @GetMapping("/list")
    public TableDataInfo list(NbChapterMaterial nbChapterMaterial)
    {
        startPage();
        List<NbChapterMaterial> list = nbChapterMaterialService.selectNbChapterMaterialList(nbChapterMaterial);
        return getDataTable(list);
    }

    /**
     * 导出章节/学习资料列表
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_material:export')")
    @Log(title = "章节/学习资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NbChapterMaterial nbChapterMaterial)
    {
        List<NbChapterMaterial> list = nbChapterMaterialService.selectNbChapterMaterialList(nbChapterMaterial);
        ExcelUtil<NbChapterMaterial> util = new ExcelUtil<NbChapterMaterial>(NbChapterMaterial.class);
        util.exportExcel(response, list, "章节/学习资料数据");
    }

    /**
     * 获取章节/学习资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_material:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(nbChapterMaterialService.selectNbChapterMaterialById(id));
    }

    /**
     * 新增章节/学习资料
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_material:add')")
    @Log(title = "章节/学习资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NbChapterMaterial nbChapterMaterial)
    {
        return toAjax(nbChapterMaterialService.insertNbChapterMaterial(nbChapterMaterial));
    }

    /**
     * 修改章节/学习资料
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_material:edit')")
    @Log(title = "章节/学习资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NbChapterMaterial nbChapterMaterial)
    {
        return toAjax(nbChapterMaterialService.updateNbChapterMaterial(nbChapterMaterial));
    }

    /**
     * 删除章节/学习资料
     */
    @PreAuthorize("@ss.hasPermi('teach:chapter_material:remove')")
    @Log(title = "章节/学习资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nbChapterMaterialService.deleteNbChapterMaterialByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('teach:chapter_material:list')")
    @GetMapping("/files")
    public AjaxResult files(NbChapterMaterial nbChapterMaterial){
        List<NbChapterMaterialVo> list = nbChapterMaterialService.files(nbChapterMaterial);
        return AjaxResult.success(list);
    }
}
